// minibossnpc.txt
// Like basicnpc, but character automatically talks to party when they get 
// within 6 spaces or combat starts. The dialogue is meant to only
// be said once, and not again. This script is meant to be for
// foes of the party.
// Memory Cells:
//   Cell 0 - How creature moves.
//     0 - stand still. 1 - hunts

//   Cell 3 - Dialogue node the character talks from.


begincreaturescript;

variables;

short i,target;
short tried_return = 0;
short talk_done = 0;
short last_abil;
short mess1 = 0;
short mess2 = 0;
short one_block = 0;

short curstare = -1;

body;

beginstate INIT_STATE;
	set_name(ME,"Black-Eyed Bones");
	set_level(ME,28);
	change_max_health(ME,100);
	set_boss_level(ME,0);
	set_coloradj(ME,0);
	set_scaling(ME,100);
	set_new_abil(ME,20);
	set_aggression(ME,70);
	
	set_courage(ME,100);
	set_resistance(ME,7,90);
	if (get_memory_cell(0) == 2)
		set_walk_speed(ME,0);
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
	//sf(,,);
	//begin_talk_mode();
break;

beginstate START_STATE; 

		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (get_foe_target(ME,8,0)) {

		if (dist_to_party() > 8)
			approach_char(ME,30000,7);
			else {
				do_attack();
				set_state(3);
				}
		}
		
	// Have I been hit? Strike back!
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());

		do_attack();
		set_state(3);
		}

	// if we're hostile, hunt party down
	if ((get_attitude(ME) >= 10) && (get_memory_cell(0) > 0)) {
		set_foe_target(ME,random_group_member(0));
		set_state(3);
		}		

	// if we're in combat and the above didn't give me anything to do, just
	// stop now. Otherwise, game will keep running script, and that eats up CPU time.
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking


	if (target_ok() == FALSE)
		set_state(START_STATE);

	if (curstare >= 0) {
		if (char_ok(curstare) == FALSE) {
			set_name(ME,"Black-Eyed Bones");
			print_str_color("A skeleton's target has fallen. Its eyes darken.",2);
			set_coloradj(ME,0);
			curstare = -1;
			last_abil = get_current_tick();
			}
			else if (can_see_char(curstare) == FALSE) {
				print_str_color("A skeleton can't see its target. Its eyes darken.",2);
				set_coloradj(ME,0);
				run_text_on_char(curstare,"Curse broken!",2);
				curstare = -1;
				last_abil = get_current_tick();
				}
				else if (get_char_status(curstare,5) == 0) {
					print_str_color("A target's curse is broken. The skeleton looks away. Its eyes darken.",2);
					set_coloradj(ME,0);
					run_text_on_char(curstare,"Curse broken!",2);
					curstare = -1;
					last_abil = get_current_tick();
					}
		}
	if (curstare < 0) {
		if (tick_difference(last_abil,get_current_tick()) > 0) {
			last_abil = get_current_tick();
			
			if (one_block == 0) {
				one_block = 1;
				end();
				}
			i = random_group_member(0);
			if (can_see_char(i)) {
				set_char_status(i,5,10 + difficulty());
				if (get_char_status(i,5) > 0) {
					run_char_animation(3,1,35);	
					pc_heard_sound_delay(166,100);	
					set_coloradj(ME,64);
					if (difficulty() > 1) {
						set_char_status(i,1,10 + difficulty());
						set_char_status(i,3,10 + difficulty());
						}
					set_name(ME,"Red-Eyed Bones");
					curstare = i;
					print_str_color("A skeleton begins to stare at you. Its eyes glow red.",2);
					run_text_on_char(ME,"Eyes glow!",2);
					run_text_on_char(curstare,"Cursed!",2);
					
					if (gf(71,21) == 0) {
						sf(71,21,1);
						ok_dlog(23,2);
						}
					}
				}	
			
			end();

			}
		}
		else {
			if (tick_difference(last_abil,get_current_tick()) > 1 + difficulty()) {
				last_abil = get_current_tick();
				run_char_animation(3,1,35);	
				pc_heard_sound_delay(195,100);	
				print_str_color("A skeleton's eyes flash bright red. The curse completes its lethal work",2);
				run_text_on_char(ME,"Eyes darken.",2);
				run_text_on_char(curstare,"Final curse.",2);
				
				set_char_status(curstare,38,2 + difficulty());
				damage_char(curstare,50 + 300 * difficulty(),1);
			
				curstare = -1;
				set_coloradj(ME,0);
				set_name(ME,"Black-Eyed Bones");

				if (gf(71,22) == 0) {
					sf(71,22,1);
					ok_dlog(26,1);
					}
				
				end();
				}
			}

	//	run_char_animation(3,1,35);	
	//	pc_heard_sound_delay(171,100);	

	//	summon_creature(which_char);
	//	set_summon_level(which_char,1);	
	//	place_particle_num(,1051,1,8);

	//run_text_on_char(short which_char_or_group,char *text,short color)
	//add_ability(, 15, which_ability, 0);
	
	//if ((mess1 == 0) && (get_health(ME) < (get_max_health(ME) * 5) / 10)) {
	//	mess1 = 1;
	//	}
		
	if ((my_dist_from_start() >= 25) && (tried_return == 0)) {
		tried_return = 1;
		set_foe_target(ME,-1);
		return_to_start(ME,2);
		set_state(4);
		}

	do_attack();
break;

beginstate 4; // returning to start
	if (my_dist_from_start() < 10)
		set_state(START_STATE);

	// Have I been hit? Strike back!
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	return_to_start(ME,2);
break;

beginstate TALKING_STATE;
	if (get_memory_cell(3) == 0) {
		print_named_str(ME,"doesn't respond.");
		end();
		}
	talk_done = 1;
	talk_no_exit(get_memory_cell(3));
break;